package com.zy.socket.chat1;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/12/19 15:40
 **/
public class Server {
    public static void main(String[] args)  {
        DataInputStream dis =null;
                ServerSocket serverSocket = null;
        DataOutputStream dos =null;
        try {
            serverSocket = new ServerSocket(1245);
            Socket accept = serverSocket.accept();
           dis = new DataInputStream(accept.getInputStream());
             dos = new DataOutputStream(accept.getOutputStream());
            while(true){
                String str = dis.readUTF();
                System.out.println(accept.getRemoteSocketAddress()+"消息："+str);
                str="响应-"+str;
                dos.writeUTF(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                dis.close();
                dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



    }
}
